# bhp.R
# bhp pdf and cdf functions

dbhp <- function(x) {
	if(!exists('dBHP'))
		dBHP <- readBin('bhp/dbhp.bin', 'double', 120001)
	x <- round(x*1e4) + 3e4 + 1
	dBHP[sapply(x, function(x) min(max(x,1),length(dBHP)))]
}

pbhp <- function(x) {
	if(!exists('pBHP'))
		pBHP <- readBin('bhp/pbhp.bin', 'double', 120001)
	x <- round(x*1e4) + 3e4 + 1
	x <- sapply(x, function(x) min(max(x,1),length(pBHP)))
	pBHP[x]
}

# approximation of a bhp by truncating a log-normal

dbhp2 <- function(x) dlnorm(x+3.6737, 1.2620, 0.2682)
pbhp2 <- function(x) plnorm(x+3.6737, 1.2620, 0.2682)

